package com.zxp.zxpsmarthomeapk.view.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;
import com.zxp.zxpsmarthomeapk.R;
import com.zxp.zxpsmarthomeapk.base.DividerItemDecoration;
import com.zxp.zxpsmarthomeapk.model.SafeGuardInfoModle;
import com.zxp.zxpsmarthomeapk.util.ToastUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class SafeGuardFragment extends Fragment {

    @BindView(R.id.rv_safe_guard)
    RecyclerView rv_safe_guard;

    private View view_safe_guard;

    public SafeGuardFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view_safe_guard = inflater.inflate(R.layout.fragment_safe_guard, container, false);
        ButterKnife.bind(this, view_safe_guard);
        initView();
        return view_safe_guard;
    }

    private void initView() {
        List<SafeGuardInfoModle> safeGuardInfoModleList = new ArrayList<SafeGuardInfoModle>();
        safeGuardInfoModleList.add(new SafeGuardInfoModle(R.mipmap.img_camera_safe, "摄像头", "共6个"));
        safeGuardInfoModleList.add(new SafeGuardInfoModle(R.mipmap.img_door_safe, "门磁", "共6个"));
        safeGuardInfoModleList.add(new SafeGuardInfoModle(R.mipmap.img_lock_safe, "门锁", "共6个"));
        safeGuardInfoModleList.add(new SafeGuardInfoModle(R.mipmap.img_body_safe, "人体移动监测", "共2个"));

        rv_safe_guard.setLayoutManager(new LinearLayoutManager(getActivity()));
        rv_safe_guard.setAdapter(new CommonAdapter<SafeGuardInfoModle>(getActivity(), R.layout.rv_safe_guard_info_item, safeGuardInfoModleList) {
            @Override
            protected void convert(final ViewHolder holder, final SafeGuardInfoModle safeGuardInfoModle, final int position) {
                holder.setText(R.id.tv_item_device, safeGuardInfoModle.getTv_item());
                holder.setText(R.id.tv_item_safe_info, safeGuardInfoModle.getTv_item_info());
                holder.setImageResource(R.id.iv_item, safeGuardInfoModle.getImage_item());
                holder.setOnClickListener(R.id.cv_item, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        ToastUtils.showToast(getActivity(), "2222");
                    }
                });
            }
        });
        rv_safe_guard.setItemAnimator(new DefaultItemAnimator());
        rv_safe_guard.addItemDecoration(new DividerItemDecoration(
                getActivity(), DividerItemDecoration.HORIZONTAL_LIST));
    }
}
